package com.quanquan.store.service;

import com.quanquan.store.entity.StoreCommercial;
import com.quanquan.store.repository.StoreCommercialRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.DateUtils;
import utils.UUIDGenerator;

import java.util.Date;
import java.util.List;


/**
 * @ClassName:StoreCommercialService
 * @Description:商户业态关联查询
 * @Author:xiongjunbao
 * @Date:2019/3/12 18:04
 * @Version 1.0
 */
@Service
public class StoreCommercialService {

    @Autowired
    private StoreCommercialRepository storeCommercialRepository;

    /**
     * 绑定商户与业态的关系
     *
     * @param commercialList
     * @param storeId
     * @return
     */
    public boolean saveStoreCommercial(List<String> commercialList,String storeId) {
        Date date = new Date();
        for (String commercialId : commercialList){
            StoreCommercial storeCommercial = new StoreCommercial();
            storeCommercial.setId(UUIDGenerator.getUUID());
            storeCommercial.setCommercialId(commercialId);
            storeCommercial.setStoreId(storeId);
            storeCommercial.setStatusRemove(0);
            storeCommercial.setStatusShow(0);
            storeCommercial.setCreateTime(DateUtils.dateToString(date, DateUtils.TIMESTAMP));
            storeCommercial.setUpdateTime(DateUtils.dateToString(date, DateUtils.TIMESTAMP));
            storeCommercialRepository.saveAndFlush(storeCommercial);
        }
        return true;
    }


}
